package com.tencent.yumeko;

import com.tencent.cloud.polaris.config.annotation.PolarisConfigKVFileChangeListener;
import com.tencent.cloud.polaris.config.listener.ConfigChangeEvent;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public final class PersonConfigChangeListener {

    /**
     * PolarisConfigKVFileChangeListener Example .
     * @param event instance of {@link ConfigChangeEvent}
     */
    @PolarisConfigKVFileChangeListener(interestedKeyPrefixes = "teacher")
    //@PolarisConfigKVFileChangeListener实现针对指定的配置属性名称或者属性前缀进行监听，
    // 配置发生变更时会触发方法回调。注意：目前只支持 KV 结构的配置文件监听
    public void onChange(ConfigChangeEvent event) {
        Set<String> changedKeys = event.changedKeys();

        for (String changedKey : changedKeys) {
            System.out.printf("%s = %s \n", changedKey, event.getChange(changedKey));
        }
    }

}